/**
 * 管理初始化
 */
var DataReceiveLog = {
    id: "DataReceiveLogTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1,
	logsInterval:null
};

/**
 * 初始化表格的列
 */
DataReceiveLog.initColumn = function () {
    return [
		{visible: false},
        {title: 'ID', field: 'id', align: 'center', valign: 'middle', width: 2, sortable: true},
        {title: '数据类型', field: 'action', align: 'center', valign: 'middle', width: 2, sortable: true},
        {title: '入参', field: 'message', align: 'center', valign: 'middle', width: 8, sortable: true,formatter:function(value,row,index){
				return "<a title='详情' onclick='messageDetail(&apos;"+row.id+"&apos;,&apos;message&apos;)'>"+row.message+"</a>";
			}},
		{title: '是否错误', field: 'isError', align: 'center', valign: 'middle', width: 1, sortable: true, formatter:function(value, row, index)
			{
				if(row.error==''){
					return '<span class="label label-success">正常</span>';
				}else{
					return '<span class="label label-danger">错误</span>';
				}
			}},
        {title: '错误信息', field: 'error', align: 'center', valign: 'middle', width: 6, srtable: true,formatter:function(value,row,index){
				return "<a title='详情' onclick='messageDetail(&apos;"+row.id+"&apos;,&apos;error&apos;)'>"+row.error+"</a>";
			}},
        {title: '时间', field: 'receiveTime', align: 'center', valign: 'middle', width: 3, srtable: true},
		{title: '是否已读', field: 'isRead', align: 'center', valign: 'middle', width: 3, srtable: false,formatter:function(value,row,index){
			if(row.isRead == 1){
				return '<span class="label label-success">已读</span>';
			}else{
				return '<span class="label label-danger">未读</span>';
			}
		}}
        ];
};

function messageDetail(id,type){

	var ajax = new $ax(Sys.backendPath + "/cdc/cdcDataReceiveLog/fieId", function(data){

		data = data.replace(/\n|\r\n/g,"<br>");
	    var index = layer.open({
	        type: 1,
	        title: '详情',
	        area: ['900px', '420px'], //宽高
	        fix: false, //不固定
	        //maxmin: true,
	        content: data
	    });
    },function(data){
        Sys.error("查询失败!" + data.responseJSON.message + "!");
    });
	var params = {};
	params.id = id;
	params.type = type;
	ajax.set(params);
    ajax.start();
}


/**
 * 打开查看详情
 */
DataReceiveLog.edit = function (id) {
	var flag = false;
	if(id){
		flag = true;
	}else if (this.check()) {
        id = this.seItem.id;
        flag = true;
    }
	if (flag) {
    	var index = Sys.open('详情',Sys.backendPath + '/cdc/kettlejoblog/to_update/' + id,['800px', '420px']);
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
DataReceiveLog.del = function (id,name) {
	var flag = false;
	if(id){
		flag = true;
	}else if (this.check()) {
        id = this.seItem.id;
        name = this.seItem.name
        flag = true;
    }
	if (flag) {
        var operation = function(){
	        var ajax = new $ax(Sys.backendPath + "/cdc/kettlejoblog/delete", function (data) {
	            Sys.success("删除成功!");
				DataReceiveLog.table.refresh();
	        }, function (data) {
	            Sys.error("删除失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("kettleJobLogId",id);
	        ajax.start();
	    };
	    Sys.confirm("是否删除?",operation);
    }
};
/**
 * 查询日志列表
 */
DataReceiveLog.search = function () {
	DataReceiveLog.table.refresh({query: DataReceiveLog.formParams()});
};
DataReceiveLog.formParams = function() {
	var queryData = {};
	queryData['startDate'] = $("#startDate").datebox("getValue");
	queryData['endDate'] = $("#endDate").datebox("getValue");
	queryData['action'] = $("#action").val();
	queryData['message'] = $("#message").val();
	queryData['error'] = $("#error").val();
	queryData['logType'] = $("input[name='logType']").val();
	return queryData;
}
$(function () {
    var defaultColunms = DataReceiveLog.initColumn();
    var table = new BSTable(DataReceiveLog.id, Sys.backendPath + "/cdc/cdcDataReceiveLog/list", defaultColunms);
    table.setPaginationType("server");
	table.setQueryParams(DataReceiveLog.formParams());
	table.setPageSize(10)
	table.setSubHeight(-27)
	DataReceiveLog.table = table.init();
});
